package com.wslNB.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/springBoot")
public class SpringBootController {
    

    @Value("${name}")
    private String name; //zhangsan
    @Value("${pp.name}")
    private String name2;//zhangsan
    @Value("${person.name}")
    private String name3;
    @Value("${address[0]}")
    private String name4;
    @Value("${msg1}")
    private String name5;
    @Value("${msg2}")
    private String name6;


    //第二种方式
    @Autowired
    private Environment env;

    @GetMapping("/index")
    public String index(){

        System.out.println(name);
        System.out.println(name2);
        System.out.println(name3);
        System.out.println(name4);
        System.out.println(name5);
        System.out.println(name6);
        System.out.println("=============");
        System.out.println(env.getProperty("name"));
        System.out.println(env.getProperty("pp.name"));
        System.out.println(env.getProperty("person.name"));
        System.out.println(env.getProperty("address[0]"));
        System.out.println(env.getProperty("address[1]"));
        System.out.println(env.getProperty("msg1"));
        System.out.println(env.getProperty("msg2"));


        return name;

    }
}
